package com.powerteam;

import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import com.powerteam.config.PowerTeamConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.Resource;

/**
 * 启动类
 *
 * @Author jinming.zhang
 * @Date 2021/11/30
 */
@SpringBootApplication
@EnableScheduling
@NacosPropertySource(dataId = "graduation-project.properties", autoRefreshed = true)
public class PowerTeamApplication implements ApplicationListener<ContextRefreshedEvent> {

    public static void main(String[] args) {
        SpringApplication.run(PowerTeamApplication.class, args);
    }

    @Resource
    private PowerTeamConfig powerTeamConfig;

    @Override
    public void onApplicationEvent(final ContextRefreshedEvent event) {

        // 动态获取网络路径信息
        powerTeamConfig.setWebRoot(event.getApplicationContext().getApplicationName() + "/");
        powerTeamConfig.setAbsoluteWebRoot(this.getClass().getResource("/").getPath().replaceFirst("/", ""));
    }
}
